import menu_engine

import debug as testing

class main_menu(object): 
    
    def __init__(self,x=1200,y=800,level=0):
        # Assigns buttons and graphics for main menu
        self.menu_engine = menu_engine.gui(x,y,level)
        self.load_main_menu()
     

####        self.menu_engine.build_menu(self.main_menu_dict)
####        self.menu_engine.input_loop()

        ##### GUI Elements (data structure)
##button: "name" : [0"button",1(x_center,y_center),2"image_name_",3"text",4clicked?,5NULL,6NULL,7"FONTFILE",8FUNCTION-TO-CALL]
##background: "name" : [0"background",1("list","of","backgrounds"),2NULL,3NULL, 4SUBTYPE,5[METADATA]]
##            subtypes:
##                Static - Static image - chosen randomly from list in index 1
##                Drift - Overlays several images and makes them drift by at different rates. Overlays are loaded from list in index one: in order, and are placed from the bottom to the top
                
##label: "name": [0"label",1(x_center,y_center),"text-string","FONTFILE",NULL,NULL]
##text_input: "name": [0"text_input",1(x_center,y_centre),2background_colour(RGB),3border_colour(RGB),4font_colour(RGB),5(Width,Height,Border_thickness),6"FONTFILE",7"IMAGEFILE",8NULL,9NULL]
##radio: "name": [0"radio",1(x_center,y_centre),2background_colour(RGB),3border_colour(RGB),4font_colour(RGB),5(Width,Height,Border_thickness),6"FONTFILE",7"IMAGEFILE_",8NULL,9NULL]
##checkbox: "name": [0"check",1(x_center,y_centre),2background_colour(RGB),3border_colour(RGB),4font_colour(RGB),5(Width,Height,Border_thickness),6"FONTFILE",7"IMAGEFILE",8NULL,9NULL]
##slider: "name": [0"slider",1(x_center,y_centre),2background_colour(RGB),3border_colour(RGB),4(Width,Height,Border_thickness),5"UP_ARROW_IMG",6"DOWN_ARROW_IMG",7"SLIDER_IMG",8NULL,9NULL]
##list: "name": [0"list",1(x_center,y_centre),2background_colour(RGB),3border_colour(RGB),4font_colour(RGB),5(Width,Height,Border_thickness),6"FONTFILE",7"IMAGEFILE",8"LIST",9NULL,10NULL]
##dropdown: "name": [0"dropdown",1(x_center,y_centre),2background_colour(RGB),3border_colour(RGB),4font_colour(RGB),5(Width,Height,Border_thickness),6"FONTFILE",7"IMAGEFILE",8"LIST",9NULL,10NULL]
##unique: "name": [0"unique",1FUNCTION-TO-CALL(data to feed function with)]
        
    # The callback for the options menu. This function is called when the user clicks the 'options' button
    def call_quit(self):
        self.menu_engine.close_gui("GUI was closed by user action")
    def load_main_menu(self):
        self.main_menu_dict={
        "cpgn_button" : ["button",(100,580), "button_long_","campaign",0,"IMAGE_FILE","IMAGE_RECT","font_16x16_pos",self.call_quit],
        "skrm_button" : ["button",(300,580), "button_long_","skirmish",0,"IMAGE_FILE","IMAGE_RECT","font_16x16_pos",self.call_quit],
        "opt_button" : ["button",(500,20), "button_long_","options",0,"IMAGE_FILE","IMAGE_RECT","font_16x16",self.load_options],
        "loadout_button" : ["button",(500,580), "button_long_","unit loadout",0,"IMAGE_FILE","IMAGE_RECT","font_16x16_pos",self.load_loadout_editor],
        "exit_button" : ["button",(700,20), "button_long_", "exit",0,"IMAGE_FILE","IMAGE_RECT","font_16x16_pos",self.call_quit],
        "help_button" : ["button",(700,580), "button_long_","help",0,"IMAGE_FILE","IMAGE_RECT","font_16x16_pos",self.call_quit],
        "user_button" : ["button",(100,20), "button_long_","user control",0,"IMAGE_FILE","IMAGE_RECT","font_16x16_neg",self.call_quit],
        "editor_but" : ["button",(300,20), "button_med_","dev editor",1,"IMAGE_FILE","IMAGE_RECT","font_16x16_neg",self.call_quit],
        "bg_0" : ["background",("test_0","test_1"),"IMAGE_FILE","IMAGE_RECT"],
        "bg_1" : ["background",("overlay_red_test","overlay_blue_test"),"IMAGE_FILE","IMAGE_RECT"],
        }
        self.menu_engine.build_menu(self.main_menu_dict)

    def load_options(self):
        options_menu={
        "exit_button" : ["button",(700,20), "button_long_", "exit",0,"IMAGE_FILE","IMAGE_RECT","font_16x16_pos",self.call_quit],
        "back_button" : ["button",(300,20), "button_long_", "back",0,"IMAGE_FILE","IMAGE_RECT","font_16x16_pos",self.load_main_menu],
        "bg_0" : ["background",("circuit","circuit2","circuit3"),"IMAGE_FILE","IMAGE_RECT"],
        }
        self.menu_engine.build_menu(options_menu)

    def load_loadout_editor(self):
        loadout_editor_menu={
        "exit_button" : ["button",(700,20), "button_long_", "exit",0,"IMAGE_FILE","IMAGE_RECT","font_16x16_pos",self.call_quit],
        "viewer" : ["button",(400,300), "button_long_", "unit viewer",0,"IMAGE_FILE","IMAGE_RECT","font_16x16_pos",self.call_quit],
        "back_button" : ["button",(300,20), "button_long_", "back",0,"IMAGE_FILE","IMAGE_RECT","font_16x16_pos",self.load_main_menu],
        "bg_0" : ["background",("circuit","circuit2","circuit3"),"IMAGE_FILE","IMAGE_RECT","drift"],
        }
        # Tell the GUI engine to load the options menu, as defined by the options_menu dictionary

        self.menu_engine.build_menu(loadout_editor_menu)



def main():
    stuff = main_menu(800,600,5)
    # Call the GUI engine to render the main menu
    stuff.menu_engine.build_menu(stuff.main_menu_dict)
    stuff.menu_engine.input_loop()
    
        
# When this file is executed directly, the global variable '__name__' has the value '__main__'
if __name__ == '__main__':
    main()
        
           
            
            
        
